package S02lianbiao;

public class T0206 {
    public static class ListNode {
        int val;
        ListNode next;

        ListNode() {
        }

        ListNode(int val) {
            this.val = val;
        }

        ListNode(int val, ListNode next) {
            this.val = val;
            this.next = next;
        }
    }

    public static void main(String[] args) {
        //添加
        int[] arr = {1, 2, 3, 4, 5, 6, 7};
        ListNode head = new ListNode(0);
        ListNode temp = head;
        for (int i = 0; i < arr.length; i++) {
            temp.next = new ListNode(arr[i]);
            temp = temp.next;
        }

        //执行
        head=reverseList(head);


        //打印
        temp = head;
        String str = new String("[");
        while (temp != null) {
            str = str + temp.val + ",";
            temp = temp.next;
        }
        str = str + "]";
        System.out.println(str);



    }

    public static ListNode reverseList(ListNode head) {
        ListNode fast = head;
        ListNode slow = null;
        ListNode temp=null;
        while (fast != null) {

            temp = fast.next;
            fast.next = slow;
            slow = fast;
            fast = temp;
        }
        return slow;


    }
}
